Skip to main content

All Questions

0votes
2answers
300views

Appropriate design pattern for providing a default Argparse instance, eliminating boilerplate

I'm using argparse.ArgumentParser extensively; however, it comes with a lot of boilerplate to set up, and this is especially noticeable when you've got more than a few common arguments that probably ...
g_elef's user avatar
2votes
2answers
159views

OOP Best practices: Is there any reason to separate out Factory functionality from an abstract base class?

Consider the following python3 code: from abc import ABC, abstractmethod class Food(ABC): _food_factory_map = {} _recipes = {} @classmethod def getFood(cls, foodName): return ...
raghavj's user avatar
-4votes
1answer
84views

How to use DRY methods with OS commands with Python and classes

My goal is to learn more about OOP patterns and use DRY principles. I am trying this for wrapping an os command that interacts with a database using classes: This works fine: import subprocess class ...
james6125's user avatar
4votes
1answer
230views

Is using getters to exchange information between objects acceptable?

Suppose I have the following Character, Potion, and PotionType classes: class Player: def __init__(self, name: str, health: int, mana: int): self._name = name self._attributes: ...
user avatar
-1votes
1answer
373views

The pythonic way: replacing interfaces with ducktyping vs inheritence

tldr: I have consumer-like classes that require a number of pieces of information to do their job. It's an "all or nothing" kind of thing: the "producers" providing them with data need to provide all ...
Conor Mancone's user avatar
3votes
2answers
1kviews

Is “A programmer-defined type.” a right definition of "class" in Python?

In Think Python 2e "class" is defined as "A programmer-defined type. A class definition creates a new class object." But isn't a built-in type considered a class too? Using Python 3.4.0, the ...
Mahmood Muhammad Nageeb's user avatar
2votes
3answers
2kviews

Is extension of an abstract parent class with an abstract child class bad design?

Is it bad design to have an abstract class inherit from another abstract class? I have a single base node (class BaseNode) and 3 possible child node types (Sink, Process, and Source). Is the ...
user avatar
7votes
2answers
10kviews

How many types of polymorphism are there in the Python language?

I just read an article by Luca Cardelli and he explained types of polymorphism which are: The article is named On Understanding Types, Data Abstraction, and Polymorphism. Types of Polymorphism ...
Pythonist's user avatar
54votes
5answers
40kviews

Are Python mixins an anti-pattern?

I'm fully aware that pylint and other static analysis tools are not all-knowing, and sometimes their advice must be disobeyed. (This applies for various classes of messages, not just conventions.) If ...
cat's user avatar
  • 734
5votes
1answer
513views

Object-Oriented design to create Images in Python

I'm creating images with centered text. I use Python but I'm faced with many question regarding how to write my class. I know that A class must aim to do one thing and do it well. Well, the one ...
Javittoxs's user avatar
1vote
1answer
791views

Building Data abstraction for rational numbers using "objects"

I follow this definition of "object":An object is a value exporting a procedural interface to data or behavior. Objects use procedural abstraction for information hiding, not type abstraction. Object ...
overexchange's user avatar
-2votes
1answer
2kviews

Why every value is an object in python? [closed]

I know about writing programs (using C) that have: Data values, that are manipulated. For example: integer, float values etc.. functions (rules), by which data values are manipulated. object is a ...
overexchange's user avatar
4votes
1answer
323views

What is the advantage of determining scopes statically and using them dynamically in case of Python?

Firstly let me clarify that I know C and am learning Python. So my OOPS is kind of bad. I was reading the official tutorial and found this Although scopes are determined statically, they are used ...
Aseem Bansal's user avatar

close